=begin rdoc
Definition File for 1129-reduced-initset.evl eventset

Author::    Matthias Woehrle  (mailto:matthias.woehrle@tik.ee.ethz.ch)
Copyright:: Copyright (c) 2008 ETH Zurich
License::   

TODO:

MISSING:

=end
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
require "rupeas"

Rupeas.new do

Type :senddone do
 with :name=>:ack, :fieldtype => :integer,  :range => [0,1],:notification => :warning
 with :name=>:dest, :fieldtype => :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61], :notification => :warning
 with :name=>:nodeid,:fieldtype=> :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61], :notification => :error
 with :name=>:origin, :fieldtype => :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61],:notification => :error
 with :name=>:seqNo, :fieldtype=> :periodic, :range => 0..255, :notification => :error
 with :name=>:time, :fieldtype => :integer, :notification => :warning
end


Type :received do
 with :name=>:dest, :fieldtype => :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61], :notification => :warning
 with :name=>:nodeid, :fieldtype => :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61], :notification => :error
 with :name=>:origin, :fieldtype => :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61],:notification => :error
 with :name=>:seqNo, :fieldtype=> :periodic, :range => 0..255, :notification => :error
 with :name=>:time, :fieldtype => :integer, :notification => :warning

end

Type :measure do
 with :name=>:nodeid, :fieldtype => :integer, :range => [0, 2, 5, 7, 10, 11, 21, 26, 29, 30, 33, 40, 41, 42, 43, 44, 60, 61], :notification => :warning
 with :name=>:measured, :fieldtype => :float, :range => {:upper=>1.0, :lower=>-12.3} , :notification => :warning
end

all = loadlog('1129-reduced-initset.evl.shorttest')

routestart_temp = all.predicate(1){|send| send[:origin] == send[:nodeid] and send[:type] == :senddone}
puts "routestart_temp :\n #{routestart_temp[:matched].length}"

routestart = transform(routestart_temp, :merge, 1) do |e1|
     {
       :type => :routestart,
       :nodeid => e1[:nodeid],
       :seqNo => e1[:seqNo],
       :origin => e1[:origin]
     }
     end


#TODO: Great Danger - Single Assignment works here and fucks up the results without any warning!!!!
pairs_temp = routestart.predicate(2){|send,receive| send[:type] == :routestart and send[:seqNo] == receive[:seqNo] and\
      receive[:type] == :received and send[:origin] == receive[:origin]}

puts "pairs_temp :\n #{pairs_temp[:matched].length}"


pairs = transform(pairs_temp, :merge, 2) do |send, receive|
      {
       :type => :pair,
       :nodeid => receive[:nodeid],
       :seqNo => send[:seqNo],
       :origin => send[:origin]
     }
    end
    
puts routestart.length
puts pairs.length


puts (pairs[:type => :pair].length).to_f / pairs[:type => :routestart].length

end